<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/18 19:37
 */

namespace module\user\front\input;

use mof\Request;

/**
 * 用户资料输入
 * @property string $nickname 昵称
 * @property string $avatar 头像
 */
class ProfileInput
{
    protected array $attrs = [
        'nickname', 'avatar', 'gender'
    ];

    public function __construct(protected array $data)
    {
    }

    public static function __make(Request $request): static
    {
        $data = $request->withValidate([
            'nickname' => 'requireWithout:avatar|chsDash',
            'gender'   => 'in:0,1,2'
        ], [
            'nickname.chsDash' => '昵称只能使用汉字、字母和数字',
            'gender.in'        => '性别无效',
        ])->post();

        return new self($data);
    }

    public function __get($name)
    {
        return $this->data[$name] ?? null;
    }

    public function data(): array
    {
        return $this->data;
    }
}